{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "052c23c3-e1a8-41aa-8426-940e522e7de6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "    名称     单价   数量\n",
      "0  小太阳  320.9  100\n",
      "1   鼠标  128.0   50\n",
      "2   小刀    1.5  200\n",
      "查看所有元素的值： [['小太阳' 320.9 100]\n",
      " ['鼠标' 128.0 50]\n",
      " ['小刀' 1.5 200]]\n",
      "查询所有元素的类型： 名称     object\n",
      "单价    float64\n",
      "数量      int64\n",
      "dtype: object\n",
      "查看所有行名称： [0, 1, 2]\n",
      "    名称     单价   数量\n",
      "1  小太阳  320.9  100\n",
      "2   鼠标  128.0   50\n",
      "3   小刀    1.5  200\n",
      "查看列索引:  Index(['名称', '单价', '数量'], dtype='object')\n",
      "  商品名称   最新单价  实时数量\n",
      "1  小太阳  320.9   100\n",
      "2   鼠标  128.0    50\n",
      "3   小刀    1.5   200\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "## 列表方式创建DataFrame对像\n",
    "data=[['小太阳', 320.9, 100], ['鼠标', 128, 50], ['小刀', 1.5, 200]]\n",
    "columns=['名称', '单价', '数量']\n",
    "df=pd.DataFrame(data=data, columns=columns)\n",
    "print(df)\n",
    "print('查看所有元素的值：', df.values)\n",
    "print('查询所有元素的类型：',df.dtypes)\n",
    "print('查看所有行名称：', list(df.index))\n",
    "df.index=[1,2,3]\n",
    "print(df)\n",
    "print('查看列索引: ',df.columns)\n",
    "df.columns=['商品名称','最新单价','实时数量']\n",
    "print(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "f9cb89d5-4027-4fdd-b874-dc531c90ef9f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "               1      2     3\n",
      "商品名称  小太阳   鼠标  小刀\n",
      "最新单价   320.9  128.0   1.5\n",
      "实时数量     100     50   200\n",
      "查看前N条数据\n",
      "   商品名称  最新单价  实时数量\n",
      "1   小太阳     320.9       100\n",
      "查看最后N条数据\n",
      "   商品名称  最新单价  实时数量\n",
      "3     小刀       1.5       200\n"
     ]
    }
   ],
   "source": [
    "# 行列数据的转换\n",
    "pd.set_option('display.unicode.east_asian_width', True)  # 规整 格式\n",
    "new_df=df.T\n",
    "print(new_df)\n",
    "\n",
    "print('查看前N条数据\\n', df.head(1))\n",
    "print('查看最后N条数据\\n', df.tail(1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "ddb49c38-5e49-44fe-a3e7-76b8ba79f197",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "行 3 列 3\n"
     ]
    }
   ],
   "source": [
    "# 查看行和列\n",
    "print('行', df.shape[0], '列', df.shape[1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "c9dff000-25af-4afc-b0d1-34866f4d2668",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "查看索引、数据类型、内存信息\n",
      " <bound method DataFrame.info of   商品名称  最新单价  实时数量\n",
      "1   小太阳     320.9       100\n",
      "2     鼠标     128.0        50\n",
      "3     小刀       1.5       200>\n"
     ]
    }
   ],
   "source": [
    "print('查看索引、数据类型、内存信息\\n', df.info)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
